using System;
namespace AGame.TabOrm
{
    [AttributeUsage(AttributeTargets.Class)]
    public class Table : Attribute
    {
        ///路径
        public readonly string Path;

        ///编码
        ///ConfigPath为false时生效，ConfigPath为true时仅保存时生效
        public readonly string Encode = "GBK";

        ///0：不按ID索引
        ///1：单Key
        ///2+：多Key（注意哈希冲突）
        public int KeyNum = 1;

        ///是否有描述行
        public bool HasDesc = true;

        ///创建列表，0或者值大于等于KeyNum为不创建，这个值必须小于KeyNum
        /// 创建的是用ID去映射一个列表
        public int BuildList = 0;

        ///是否排序保存
        public bool SaveSort = false;

        /// 是否使用项目配置表路径
        public bool ConfigPath = true;
        
        public string ResourcesPath;
        
        /// 延时读表, BuildList大于0则直接为false
        public bool DelayRead = true;

        public Table(string path)
        {
            Path = path;
        }

        public bool IsDelayRead()
        {
            return BuildList <= 0 && DelayRead;
        }
    }

    /// <summary>
    /// 自定义名字或基类
    /// </summary>
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
    public class TabField : Attribute
    {
        public string Name;

        public TabField(string name = null)
        {
            Name = name;
        }

        public virtual Func<string, object> GetStrToObjFunc(Type tabType, Type targetType)
        {
            return null;
        }

        public virtual Func<object, string> GetObjToStrFunc(Type tabType, Type targetType)
        {
            return null;
        }
    }

    

    

    /// <summary>
    /// 保存前调用
    /// </summary>
    [AttributeUsage(AttributeTargets.Method)]
    public class TabSaveBefore : Attribute
    {
    }

    /// <summary>
    /// 保存后调用
    /// </summary>
    [AttributeUsage(AttributeTargets.Method)]
    public class TabSaveAfter : Attribute
    {
    }

    /// <summary>
    /// 初始化调用
    /// </summary>
    [AttributeUsage(AttributeTargets.Method)]
    public class TabInitialize : Attribute
    {
    }
}